﻿using System.Web.UI.WebControls;
using System.Xml;


    public class SetControlCommon
    {
        #region TreeManiputlation
        public static void GetPrdtTreeView(TreeView tv,string path,string param)
        {
            tv.Nodes.Clear();
            XmlDocument doc = new XmlDocument();
            doc.Load(path);
            XmlNodeList nodes = doc.SelectNodes("//SysRoot/BehindManage[@id='" + param + "']/module");
            XmlNodeList nodesChild = doc.SelectNodes("//SysRoot/BehindManage[@id='" + param + "']/module/interface");
            foreach (XmlNode xn in nodes)
            {
                TreeNode tn = new TreeNode(xn.Attributes["tittle"].Value, xn.Attributes["tittle"].Value);
                tn.NavigateUrl = xn.Attributes["url"].Value;
                tv.Nodes.Add(tn);
            }
            switch (param)
            {
                case "prdt":
                    {
                        GetProductTree(tv, nodesChild);
                    }; break;
                case "order":
                    {
                        GetSupplierTree(tv, nodesChild);
                    }; break;
                case "sys":
                    {
                        GetSystemTree(tv, nodesChild);
                    } break;
                case "super":
                    {
                        GetSuperTree(tv, nodesChild);
                    } break;
                     
            }

            //Master.MasterTreeView = tv;
        }

        private static void GetSuperTree(TreeView tv, XmlNodeList nodesChild)
        {
            foreach (XmlNode xn in nodesChild)
            {
                TreeNode tn = new TreeNode(xn.Attributes["tittle"].Value);
                tn.NavigateUrl = xn.Attributes["url"].Value;
                switch (xn.ParentNode.Attributes["tittle"].Value)
                {
                    case "管理员设置": tv.FindNode("管理员设置").ChildNodes.Add(tn); break;
                }
            }
        }

        private static void GetSystemTree(TreeView tv, XmlNodeList nodesChild)
        {
            foreach (XmlNode xn in nodesChild)
            {
                TreeNode tn = new TreeNode(xn.Attributes["tittle"].Value);
                tn.NavigateUrl = xn.Attributes["url"].Value;
                switch (xn.ParentNode.Attributes["tittle"].Value)
                {
                    case "系统管理": tv.FindNode("系统管理").ChildNodes.Add(tn); break;
                }
            }
        }

        private static void GetSupplierTree(TreeView tv, XmlNodeList nodesChild)
        {
            foreach (XmlNode xn in nodesChild)
            {
                TreeNode tn = new TreeNode(xn.Attributes["tittle"].Value);
                tn.NavigateUrl = xn.Attributes["url"].Value;
                switch (xn.ParentNode.Attributes["tittle"].Value)
                {
                    case "订单": tv.FindNode("订单").ChildNodes.Add(tn); break;
                }
            }
        }

        private static void GetProductTree(TreeView tv, XmlNodeList nodesChild)
        {
            foreach (XmlNode xn in nodesChild)
            {
                TreeNode tn = new TreeNode(xn.Attributes["tittle"].Value);
                tn.NavigateUrl = xn.Attributes["url"].Value;
                switch (xn.ParentNode.Attributes["tittle"].Value)
                {
                    case "商品管理": tv.FindNode("商品管理").ChildNodes.Add(tn); break;
                    case "类型管理": tv.FindNode("类型管理").ChildNodes.Add(tn); break;
                    case "品牌标签管理": tv.FindNode("品牌标签管理").ChildNodes.Add(tn); break;
                    case "供应商": tv.FindNode("供应商").ChildNodes.Add(tn); break;
                }
            }
        }
        #region Past
        //public static void GetSupplierTreeview(TreeView tv,string path)
        //{
        //    tv.Nodes.Clear();
        //    XmlDocument doc = new XmlDocument();
        //    doc.Load(path);
        //    XmlNodeList nodes = doc.SelectNodes("//ProductManage/module");
        //    XmlNodeList nodesChild = doc.SelectNodes("//ProductManage/module/interface");
        //    foreach (XmlNode xn in nodes)
        //    {
        //        TreeNode tn = new TreeNode(xn.Attributes["tittle"].Value, xn.Attributes["tittle"].Value);
        //        tn.NavigateUrl = xn.Attributes["url"].Value;
        //        tv.Nodes.Add(tn);
        //    }
        //    foreach (XmlNode xn in nodesChild)
        //    {
        //        TreeNode tn = new TreeNode(xn.Attributes["tittle"].Value);
        //        tn.NavigateUrl = xn.Attributes["url"].Value;
        //        switch (xn.ParentNode.Attributes["tittle"].Value)
        //        {
        //            case "供应商": tv.FindNode("供应商").ChildNodes.Add(tn); break;
        //        }
        //    }
        //    //Master.MasterTreeView = tv;
        //}
        #endregion
        #endregion

        #region DropDownList Maniputlation
        public static void GetDDLType(DropDownList ddl)
        {
            ddl.Items.Clear();
            GoShopping.BLL.ProductTypeBean ptb = new GoShopping.BLL.ProductTypeBean();
            ddl.DataTextField = "TypeName";
            ddl.DataValueField = "ID";
            ddl.Items.Add(new ListItem("--请选择--", "-1"));
            foreach (GoShopping.Model.ProductType pt in ptb.GetAllProductTypeList())
            {
                if (pt.ParentID != -1)
                {
                    ListItem li = new ListItem(pt.TypeName, pt.ID.ToString());
                    ddl.Items.Add(li);
                }
            }
        }
        public static void GetDDLType(DropDownList ddl,string selectedItem)
        {
            ddl.Items.Clear();
            GoShopping.BLL.ProductTypeBean ptb = new GoShopping.BLL.ProductTypeBean();
            ddl.DataTextField = "TypeName";
            ddl.DataValueField = "ID";
            ddl.Items.Add(new ListItem("--请选择--", "-1"));
            foreach (GoShopping.Model.ProductType pt in ptb.GetAllProductTypeList())
            {
                if (pt.ParentID != -1)
                {
                    ListItem li = new ListItem(pt.TypeName, pt.ID.ToString());
                    ddl.Items.Add(li);
                }
            }
            ListItem li1 = ddl.Items.FindByValue(selectedItem);
            int index = ddl.Items.IndexOf(li1);
            ddl.SelectedIndex = index;
        }
        #endregion
    }

